package com.example.myapplication.repository;

import android.app.Application;

import androidx.lifecycle.LiveData;

import com.example.myapplication.dao.NoteDao;
import com.example.myapplication.database.InitDataBase;
import com.example.myapplication.entity.Note;

import java.util.List;

public class NoteRepository {
    private NoteDao noteDao;
    private LiveData<List<Note>> allNotes;

    public NoteRepository(Application application) {
        InitDataBase db = InitDataBase.getDatabase(application);
        noteDao = db.noteDao();
        allNotes = noteDao.getAllNotes();
    }

    public LiveData<List<Note>> getAllNotes() {
        return allNotes;
    }

    public void insert(Note note) {
        InitDataBase.databaseWriteExecutor.execute(() -> {
            noteDao.insert(note);
        });
    }
}
